﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SplenetiX
{
    class SoundEngine
    {
        /* Declarations */
        static SoundEffect tir, degats, mort_Joueur, mort_Ennemi, jump;
        static Song song_1;
        static float Vol = 0.5f;

        /* Media player INItialize */
        public static void SoundEngineInitialize()
        {
            MediaPlayer.Stop();
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume = 0.25f;            
        }

        /*Loadings*/
        static public void LoadSoundEngine(ContentManager ContentManager)
        {
            tir = ContentManager.Load<SoundEffect>("SoundEngine//tir");
            degats = ContentManager.Load<SoundEffect>("SoundEngine//degats");
            mort_Joueur = ContentManager.Load<SoundEffect>("SoundEngine//Mort_Joueur");
            mort_Ennemi = ContentManager.Load<SoundEffect>("SoundEngine//Mort_Ennemi");
            jump = ContentManager.Load<SoundEffect>("SoundEngine//Jump");
            song_1 = ContentManager.Load<Song>("SoundEngine//Simian Mobile Disco -- Clock");
        }
        
        /*Gets*/
        public static SoundEffect Tir { get { return tir; } }
        public static SoundEffect Degats { get { return degats; } }
        public static SoundEffect Mort_Joueur { get { return mort_Joueur; } }
        public static SoundEffect Mort_Ennemi { get { return mort_Ennemi; } }
        public static SoundEffect Jump { get { return jump; } }
        public static Song Song_1 { get { return song_1; } }
        public static float Volume 
        {
            get { return Vol; }
            set { Vol = value; }
        }
        
        /* UpdateSound
         * Avec touches numPad1 & numPad2
         *
        */
        
        public static void VolumeControl()
        {
            if (Volume > 0.0001f)
            {
                if (ServiceHelper.Get<IKeyboardService>().IsKeyDown(Keys.NumPad1))
                {                    
                    Volume -= 0.01f;
                    MediaPlayer.Volume -= 0.01f;
                }
            }

            if (Volume < 1.0f)
            {
                if (ServiceHelper.Get<IKeyboardService>().IsKeyDown(Keys.NumPad2))
                {
                    Volume += 0.01f;
                    MediaPlayer.Volume += 0.01f;
                }
            }
        }

        /*Play Sound
         * 
         * Exemple D'utilisation :
         * 
         * SoundEngine.PlaySound(SoundEngine.Tir);
         *          
         *
        */

        static public void PlaySound(SoundEffect SoundEffect)
        {
            if(Constant.music)
                SoundEffect.Play(Vol, 0.0f, 0.0f);
        }
        static public void PlaySong(Song Song)
        {
            MediaPlayer.Play(Song);            
        }

    }
}
